home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1035
/
1035.xpi
/
chrome
/
1clickweather.jar
/
content
/
1clickweather
/
js
/
data
/
panel.js
< prev
next >
Wrap
Text File
|
2010-01-04
|
14KB
|
457 lines
// � 2005 The Weather Channel Interactive, Inc. All Rights Reserved.
jsInclude("chrome://1clickweather/content/js/config/loadconfig.js");
var oPanel = Array();
var mytm = false;
// ok, we first make a stub object that we can inherit from
function oPanelStub(){
this.id = null;
this.Panel = null;
this.Box = null;
this.CurrentLocation = null;
this.dataSrc = null;
this.initTime = null;
this.lastChangeTime = null;
this.Url = null;
this.Data = {};
var initFlag = false;
//DumperTagProperties["OPTION"] = ['text','value','defaultSelected'];
this.Dump = function(asText){
if(asText){
return(Dumper("PANEL: " + this.getID() + "\n" + this.getState()));
}else{
DumperAlert("PANEL: " + this.getID() + "\n" + this.getState());
}
}
this.init = function(id){
try{
this.id = id;
this.context = ToolbarContainers[this.id].getID() + ".Tooltip";
if(this.id && !initFlag){
this.Panel = document.createElement("statusbarpanel");
this.Panel.setAttribute("id", 'statusbar-container.' + this.id);
this.Box = document.createElement("hbox");
this.Box.setAttribute("id", this.id + ".box");
this.Panel.appendChild(this.Box);
document.getElementById(GlobalToolbarLocation).appendChild(this.Panel);
this.CurrentLocation = GlobalToolbarLocation;
this.Make();
initFlag = true;
this.initTime = now();
}
}catch(e){
debug("error in panel init: " + e);
}
}
this.Delete = function(){
document.getElementById(this.CurrentLocation).removeChild(document.getElementById(ToolbarContainers[this.id].getID()));
initFlag = false;
}
this.moveToolbar = function(){
try{
document.getElementById(this.CurrentLocation).removeChild(document.getElementById(ToolbarContainers[this.id].getID()));
document.getElementById(GlobalToolbarLocation).appendChild(this.Panel);
this.CurrentLocation = GlobalToolbarLocation;
this.lastChangeTime = now();
}catch(e){
debug("error moving panel: " + this.id + " " + e);
}
}
this.getID = function(){
return('statusbar-container.' + this.id);
}
// Hide/Show hide or show the whole panel
this.Hide = function(){
this.Panel.setAttribute("collapsed", true);
this.lastChangeTime = now();
}
this.Show = function(){
this.Panel.setAttribute("collapsed", false);
this.disableTooltip();
this.lastChangeTime = now();
//**-- We show the location, because it may be hidden by the user!
if(document.getElementById(GlobalToolbarLocation).hidden)
document.getElementById(GlobalToolbarLocation).hidden = false;
}
this.drawFromHbox = function(newHbox){
newHbox.setAttribute("class", "panelStyle");
newHbox.setAttribute("id", this.getID() + ".box");
try{
document.getElementById('statusbar-container.' + this.id).removeChild(this.Box);
this.Box = newHbox;
}
catch(e){
GlobalError.Custom("draw: " + e.message);
}
if(this.getID() != "statusbar-container.SWA"){
this.enableTooltip();
}else{
this.disableTooltip();
}
document.getElementById('statusbar-container.' + this.id).appendChild(newHbox);
this.lastChangeTime = now();
}
this.setDataSource = function(src){
// make sure there is an existing data source object to register with
if(src && (typeof(DataContainers[src]) != "undefined")){
debug("setDatasource: " + src);
DataContainers[src].Register(this.id);
this.dataSrc = src;
}
}
// Hide/ShowIcon are meant to hide or show the individual icons in the options panel
this.HideIcon = function(iconKey){
this.Data[iconKey].setAttribute("hidden", "true");
this.lastChangeTime = now();
}
this.ShowIcon = function(iconKey){
this.Reregister();
this.Data[iconKey].setAttribute("hidden", "false");
this.lastChangeTime = now();
}
this.getScreenXY = function(){
return(Array(this.Box.boxObject.screenX, this.Box.boxObject.screenY));
}
this.enableTooltip = function(){
this.Box.setAttribute("tooltip", this.getID() + ".Tooltip");
this.lastChangeTime = now();
}
this.disableTooltip = function(){
this.Box.setAttribute("tooltip", null);
try{
var parent = document.getElementById(this.getID() + ".Tooltip").parentNode;
parent.removeChild(document.getElementById(this.getID() + ".Tooltip"));
}catch(e){
debug("error del tooltip: " + this.getID() + " " + e);
}
this.lastChangeTime = now();
}
this.getState = function(){
var str = '';
var xy = this.getScreenXY();
str += 'location: ' + this.CurrentLocation + '\n';
str += 'collapsed: ' + this.Panel.getAttribute("collapsed") + '\n';
str += 'pos: x: ' + xy[0] + ' y: ' + xy[1] + '\n';
str += 'datasrc: ' + this.dataSrc + '\n';
str += 'inittime: ' + this.initTime + '\n';
str += 'changetime: ' + this.lastChangeTime + '\n';
return(str);
}
this.setLink = function(url){
this.Url = url;
}
// if we are just hitting a link directly off of the options bar...
this.Link = function(linkIndex){
var str = "";
try{
switch(linkIndex){
case 'radar':
str = GlobalAppConfig.getMapByID(GlobalUserConfig.getAllProfiles().getDefaultProfile().getRadar().getID()).getURL();
break;
case 'satellite':
str = GlobalAppConfig.getMapByID(GlobalUserConfig.getAllProfiles().getDefaultProfile().getSatelite().getID()).getURL();
break;
case 'video':
str = GlobalAppConfig.getVideoByID(GlobalUserConfig.getAllProfiles().getDefaultProfile().getVideo().getID()).getURL();
break;
case 'swa':
str = this.Url;
break;
case 'hourbyhour':
var locationId = GlobalUserConfig.getAllProfiles().getDefaultProfile().getSetup().getLocation().getLocID();
str = "http://1cwffweb.weather.com/weather/hourbyhour/"+ locationId +"?cm_ven=1CW&cm_cat=FFv1.1.9&cm_pla=wx.com-bar&cm_ite=wx-hbh&par=1CWFFv1.1.9&site=wx.com-bar";
break;
case 'tendayfcst':
var locationId = GlobalUserConfig.getAllProfiles().getDefaultProfile().getSetup().getLocation().getLocID();
str = "http://1cwffweb.weather.com/weather/tenday/"+ locationId +"?cm_ven=1CW&cm_cat=FFv1.1.9&cm_pla=wx.com-bar&cm_ite=wx-tenday&par=1CWFFv1.1.9&site=wx.com-bar";
break;
}
// alert("link: " + str);
openLinkInNewTab(str);
}catch(e){
debug("error in link: " + e);
}
}
}
// oPanel.Alert does the alert panel in the status bar
oPanel.SWA = function(){ };
oPanel.SWA.prototype = new oPanelStub;
oPanel.SWA.prototype.Make = function(){
this.Hide();
var l = new oXUL.Label(this.Box, "swa");
l.Align("center");
l.Make();
this.setDataSource('SWA');
}
// now, we make a new object based on the stub with extra functions
// The oPanel.Options handles the options icons in the status bar
oPanel.Options = function(){ };
oPanel.Options.prototype = new oPanelStub;
oPanel.Options.prototype.Reregister = function() {
//this.Data['lifestyle'].addEventListener('click',lifestyleClick,false);
this.Data['radar'].addEventListener('click',radarClick,false);
this.Data['satellite'].addEventListener('click',satelliteClick,false);
this.Data['video'].addEventListener('click',videoClick,false);
this.Data['hourbyhour'].addEventListener('click',clockClick,false);
this.Data['tendayfcst'].addEventListener('click',tendayfcstClick,false);
}
oPanel.Options.prototype.Make = function(){
/*
var lifestyle = document.createElement("hbox");
lifestyle.setAttribute("class", "panelStyle");
lifestyle.setAttribute("hidden", "true");
XULSimple.Spacer(lifestyle, 5);
var i = new oXUL.iconByID(lifestyle, "toolbar_quick");
lifestyle.addEventListener('click',lifestyleClick,false);
//i.onClick("openXUL('lifestyle.xul');");
i.setAttribute("tooltip", "quickLaunchTooltip");
i.Make();
this.Box.appendChild(lifestyle);
this.Data['lifestyle'] = lifestyle;
*/
var radar = document.createElement("hbox");
radar.setAttribute("hidden", "true");
radar.setAttribute("class", "panelStyle");
XULSimple.Spacer(radar, 5);
var i = new oXUL.iconByID(radar, "toolbar_radar");
radar.addEventListener('click',radarClick,false);
//i.onClick("ToolbarContainers['Options'].Link('radar');");
i.setAttribute("tooltip", "radarTooltip");
i.Make();
this.Box.appendChild(radar);
this.Data['radar'] = radar;
var satellite = document.createElement("hbox");
satellite.setAttribute("hidden", "true");
satellite.setAttribute("class", "panelStyle");
XULSimple.Spacer(satellite, 5);
var i = new oXUL.iconByID(satellite, "toolbar_satellite");
satellite.addEventListener('click',satelliteClick,false);
//i.onClick("ToolbarContainers['Options'].Link('satellite');");
i.setAttribute("tooltip", "sateliteTooltip");
i.Make();
this.Box.appendChild(satellite);
this.Data['satellite'] = satellite;
var video = document.createElement("hbox");
video.setAttribute("hidden", "true");
video.setAttribute("class", "panelStyle");
XULSimple.Spacer(video, 5);
var i = new oXUL.iconByID(video, "toolbar_video");
video.addEventListener('click',videoClick,false);
//i.onClick("ToolbarContainers['Options'].Link('video');");
i.setAttribute("tooltip", "videoTooltip");
i.Make();
this.Box.appendChild(video);
this.Data['video'] = video;
// ******************************************
// clock icon
// ******************************************
var hourbyhour = document.createElement("hbox");
hourbyhour.setAttribute("class", "panelStyle");
hourbyhour.setAttribute("hidden", "true");
XULSimple.Spacer(hourbyhour, 5);
var i = new oXUL.iconByID(hourbyhour, "clock");
hourbyhour.addEventListener('click',clockClick,false);//todo change
i.setAttribute("tooltip", "hourbyhourTooltip");
i.Make();
this.Box.appendChild(hourbyhour);
this.Data['hourbyhour'] = hourbyhour;
// ******************************************
// 10 day forecast icon
// ******************************************
var tendayfcst = document.createElement("hbox");
tendayfcst.setAttribute("class", "panelStyle");
tendayfcst.setAttribute("hidden", "true");
XULSimple.Spacer(tendayfcst, 5);
var i = new oXUL.iconByID(tendayfcst, "tendayfcst");
tendayfcst.addEventListener('click',tendayfcstClick,false);//todo change
i.setAttribute("tooltip", "tendayfcstTooltip");
i.Make();
this.Box.appendChild(tendayfcst);
this.Data['tendayfcst'] = tendayfcst;
}
// oPanel.CurrentCond does the alert panel in the status bar
oPanel.CurrentCond = function(){ };
oPanel.CurrentCond.prototype = new oPanelStub;
oPanel.CurrentCond.prototype.Make = function(){
this.Hide();
var l = new oXUL.Label(this.Box, "cc");
l.Align("center");
l.Tooltip(this.id);
l.Make();
this.setDataSource('Obs');
}
// oPanel.CurrentCond does the alert panel in the status bar
oPanel.Day0 = function(){ };
oPanel.Day0.prototype = new oPanelStub;
oPanel.Day0.prototype.Make = function(){
this.Hide();
var l = new oXUL.Label(this.Box, "day0");
l.Align("center");
l.Tooltip(this.id);
l.Make();
this.setDataSource('Fcst');
}
// oPanel.CurrentCond does the alert panel in the status bar
oPanel.Day1 = function(){ };
oPanel.Day1.prototype = new oPanelStub;
oPanel.Day1.prototype.Make = function(){
this.Hide();
var l = new oXUL.Label(this.Box, "day1");
l.Align("center");
l.Tooltip(this.id);
l.Make();
this.setDataSource('Fcst');
}
// oPanel.CurrentCond does the alert panel in the status bar
oPanel.Day2 = function(){ };
oPanel.Day2.prototype = new oPanelStub;
oPanel.Day2.prototype.Make = function(){
this.Hide();
var l = new oXUL.Label(this.Box, "day2");
l.Align("center");
l.Tooltip(this.id);
l.Make();
this.setDataSource('Fcst');
}
// oPanel.CurrentCond does the alert panel in the status bar
oPanel.Day3 = function(){ };
oPanel.Day3.prototype = new oPanelStub;
oPanel.Day3.prototype.Make = function(){
this.Hide();
var l = new oXUL.Label(this.Box, "day3");
l.Align("center");
l.Tooltip(this.id);
l.Make();
this.setDataSource('Fcst');
}
// oPanel.CurrentCond does the alert panel in the status bar
oPanel.Day4 = function(){ };
oPanel.Day4.prototype = new oPanelStub;
oPanel.Day4.prototype.Make = function(){
this.Hide();
var l = new oXUL.Label(this.Box, "day4");
l.Align("center");
l.Tooltip(this.id);
l.Make();
this.setDataSource('Fcst');
}
function lifestyleClick(event){
if(event.button==0 || event.button==1) {
openXUL('lifestyle.xul');
} else {
callSetup();
}
}
function radarClick(event){
if(event.button==0 || event.button==1) {
ToolbarContainers['Options'].Link('radar');
} else {
callSetup();
}
}
function satelliteClick(event){
if(event.button==0 || event.button==1) {
ToolbarContainers['Options'].Link('satellite');
} else {
callSetup();
}
}
function videoClick(event){
if(event.button==0 || event.button==1) {
ToolbarContainers['Options'].Link('video');
} else {
callSetup();
}
}
// clock icon click event handler
function clockClick(event){
if(event.button==0 || event.button==1){
ToolbarContainers['Options'].Link('hourbyhour');
}
else{
callSetup();
}
}
// 10 day forecast icon click event handler
function tendayfcstClick(event){
if(event.button==0 || event.button==1){
ToolbarContainers['Options'].Link('tendayfcst');
}
else{
callSetup();
}
}